<?php

namespace Cephalopod\SSL;

use NetworkIOEvent\StaticServer;

class IOEvent extends StaticServer
{
    private static MainLogic $mainLogic;

    public static function bind(MainLogic $mainLogic)
    {
        static::$mainLogic = $mainLogic;
    }

    public static function createNewConnection(string $host, int $port): int
    {
        return static::createConnection($host, $port);
    }

    public static function closeExistsConnection(int $id)
    {
        return static::closeConnection($id);
    }

    protected static function handleReadEvent(int $id, string &$readBuffer): int
    {
        return static::$mainLogic->handleReadEvent($id, $readBuffer);
    }

    protected static function handleWriteEvent(int $id, string &$writeBuffer)
    {
        static::$mainLogic->handleWriteEvent($id, $writeBuffer);
    }

    protected static function handleOpenEvent(int $id)
    {
        static::$mainLogic->handleOpenEvent($id);
    }

    protected static function handleCloseEvent(int $id)
    {
        static::$mainLogic->handleCloseEvent($id);
    }
}
